import hashlib
from properties import Properties

class Node:
	def __init__(self):
		self.__action = None
		self.__kind = None
		self.__path = None
		self.__copy_from_path = None
		self.__copy_from_rev = None
		self.__properties = Properties()
		self.__text = None
		self.__text_md5 = None
		self.__force_properties = False
		self.__trailing_newlines = 0
	
	def __get_action(self):
		return self.__action
	
	def __get_content_length(self):
		result = 0
		if self.text != None:
			result += len(self.text)
		if self.properties.count > 0 or self.force_properties == True:
			result += self.properties.get_length()
		return result
	
	def __get_copy_from_path(self):
		return self.__copy_from_path
	
	def __get_copy_from_rev(self):
		return self.__copy_from_rev
	
	def __get_force_properties(self):
		return self.__force_properties
	
	def __get_kind(self):
		return self.__kind
	
	def __get_path(self):
		return self.__path
	
	def __get_properties(self):
		return self.__properties
	
	def __get_text(self):
		return self.__text
	
	def __get_trailing_newlines(self):
		return self.__trailing_newlines
	
	def __get_text_md5(self):
		assert self.text != None
		if self.__text_md5 == None:
			hasher = hashlib.md5()
			hasher.update(self.text)
			self.__text_md5 = hasher.hexdigest()
		return self.__text_md5
	
	def __set_action(self, action):
		self.__action = action
	
	def __set_copy_from_path(self, copy_from_path):
		self.__copy_from_path = copy_from_path
	
	def __set_copy_from_rev(self, copy_from_rev):
		self.__copy_from_rev = copy_from_rev
	
	def __set_force_properties(self, force_properties):
		self.__force_properties = force_properties
	
	def __set_kind(self, kind):
		self.__kind = kind
	
	def __set_path(self, path):
		self.__path = path
	
	def __set_text(self, text):
		self.__text = text
	
	def __set_trailing_newlines(self, trailing_newlines):
		self.__trailing_newlines = trailing_newlines
	
	action = property(__get_action, __set_action)
	content_length = property(__get_content_length)
	copy_from_path = property(__get_copy_from_path, __set_copy_from_path)
	copy_from_rev = property(__get_copy_from_rev, __set_copy_from_rev)
	force_properties = property(__get_force_properties, __set_force_properties)
	kind = property(__get_kind, __set_kind)
	node = property(__get_path, __set_path)
	properties = property(__get_properties)
	text = property(__get_text, __set_text)
	text_md5 = property(__get_text_md5)
	trailing_newlines = property(__get_trailing_newlines, __set_trailing_newlines)
